﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.InsertLocationInsideSeam.CApIlisUIDirector
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.InsertLocationInsideSeam;

internal class CApIlisUIDirector
{
  private const int _UNEMPHASIZED_SEAMS_WIDTH = 1;
  private const int _EMPHASIZED_SEAMS_WIDTH = 3;
  private CCUiInsertLocationDlg _dialog;
  private CApIlisInsertLocInsideSeam _appManager;
  private TxPickListener _pickListener;
  private CApIlisManipulator _dummyFrame;
  private TxRoboticSeamLocationOperation _lastRelativeLocation;
  private TxRoboticSeamLocationOperation _lastBeforeAfterLocation;
  private TxRoboticSeamLocationOperation _otherSublingLocationInPickMode;
  private TxRoboticSeamLocationOperation _automaticRelativeLocation;
  private bool _shouldRefreshmanipulatorDisplay;
  private bool _shouldUpadatePositionAndRotationValues;
  private Dictionary<string, TxDisplayableObjectVisibility> _objectsVisibilityDict;

  public bool ShouldRefreshmanipulatorDisplay
  {
    get => this._shouldRefreshmanipulatorDisplay;
    set => this._shouldRefreshmanipulatorDisplay = value;
  }

  public bool ShouldUpadatePositionAndRotationValues
  {
    get => this._shouldUpadatePositionAndRotationValues;
    set => this._shouldUpadatePositionAndRotationValues = value;
  }

  private TxRoboticSeamLocationOperation RelativeLocationForColoring
  {
    set => this._lastRelativeLocation = value;
  }

  private TxRoboticSeamLocationOperation BeforeAfterLocationForColoring
  {
    set => this._lastBeforeAfterLocation = value;
  }

  private TxRoboticSeamLocationOperation OtherSublingLocationForColoring
  {
    set => this._otherSublingLocationInPickMode = value;
  }

  public CApIlisCopyUtils.CopyParametersOptions CopyParameters
  {
    get => this._appManager.CopyParameters;
    set => this._appManager.CopyParameters = value;
  }

  public CApIlisUIDirector(CCUiInsertLocationDlg dialog)
  {
    this._dialog = dialog;
    this._dialog.PercentageTxNumericEditBoxCtrl.LowerBound = 0.0;
    this._dialog.PercentageTxNumericEditBoxCtrl.UpperBound = 100.0;
    this._appManager = new CApIlisInsertLocInsideSeam();
    this._pickListener = new TxPickListener();
    this._pickListener.PickLevel = (TxPickLevel) 1;
  }

  public void LoadDialog()
  {
    TxObjectList selectedItems = this._appManager.GetSelectedItems();
    if (((Collection<ITxObject>) selectedItems).Count == 1)
    {
      TxRoboticSeamLocationOperation location = ((Collection<ITxObject>) selectedItems)[0] as TxRoboticSeamLocationOperation;
      if (TxRoboticSeamLocationOperation.op_Inequality(location, (ITxObject) null))
      {
        this._appManager.UnselectLocation((ITxObject) location);
        this._dialog.RelativeLocationObjEditBoxCtrl.Object = (ITxObject) location;
      }
    }
    this.SetGraphicsManipulatorsAndValidators();
  }

  public void DialogClosing()
  {
    if (this._objectsVisibilityDict != null)
      this.ShowPath();
    this.DestroyManipulator();
    this.UnsubscribeForPickListener();
    this._pickListener = (TxPickListener) null;
    this.UncolorLastRelativeLocation();
    this.UncolorLastBeforeAfterLocation();
    this.UnEmphasizeOnlyRelevantSeam();
  }

  private void SetGraphicsManipulatorsAndValidators()
  {
    this.SetSeamLocationValidator();
    this.SetBetween2LocationsMode();
    this.EmphasizeOnlyRelevantSeam();
  }

  private void DisplayErrorMessage()
  {
    int num = (int) TxMessageBox.Show(StringTable.CANNOT_INSERT_LOCATION_MSG, StringTable.CMD_NAME, MessageBoxButtons.OK, MessageBoxIcon.Hand);
  }

  public void RelativeLocationPicked()
  {
    if (this._dialog.PickOnCurveRadioButton.Checked)
      this.SetPickMode();
    else
      this.SetBetween2LocationsMode();
    this.OnSeamLocationChanged();
    this.EmphasizeOnlyRelevantSeam();
  }

  public void UpdateNumericControlsAccordingToTheRadioButtonCheck()
  {
    if (this._dialog.PercentageRadioButton.Checked)
    {
      this._dialog.PercentageTxNumericEditBoxCtrl.Enabled = true;
      this._dialog.DistanceTxNumericEditBoxCtrl.Enabled = false;
    }
    else if (this._dialog.DistanceRadioButton.Checked)
    {
      this._dialog.PercentageTxNumericEditBoxCtrl.Enabled = false;
      this._dialog.DistanceTxNumericEditBoxCtrl.Enabled = true;
    }
    else
    {
      this._dialog.PercentageTxNumericEditBoxCtrl.Enabled = false;
      this._dialog.DistanceTxNumericEditBoxCtrl.Enabled = false;
    }
  }

  public void SetAddNewLocationState(bool after)
  {
    this.UncolorLastBeforeAfterLocation();
    TxRoboticSeamLocationOperation locationOperation = this._dialog.RelativeLocationObjEditBoxCtrl.Object as TxRoboticSeamLocationOperation;
    if (!TxRoboticSeamLocationOperation.op_Inequality(locationOperation, (ITxObject) null))
      return;
    TxRoboticSeamOperation fromSeamLocation = TxProjectionEx.GetSeamFromSeamLocation(locationOperation);
    if (!TxRoboticSeamOperation.op_Inequality(fromSeamLocation, (ITxObject) null))
      return;
    if (!after ? this._appManager.HasLocationBefore(fromSeamLocation, locationOperation) : this._appManager.HasLocationAfter(fromSeamLocation, locationOperation))
    {
      this.UpdateNumericControlsAccordingToTheRadioButtonCheck();
      this._dialog.Translate3DVectorCtrl1.Enabled = true;
      this._dialog.OkButton.Enabled = true;
      this._dialog.ApplyButton.Enabled = true;
      this.ShouldRefreshmanipulatorDisplay = true;
      this.ShouldUpadatePositionAndRotationValues = true;
      TxTransformation locationOnDistance = this.GetLocationOnDistance();
      TxTransformation absolutePosition = this.CalculateLocationAbsolutePosition(locationOnDistance);
      if (TxTransformation.op_Inequality(absolutePosition, (TxTransformation) null))
      {
        this.PlaceManipulator(absolutePosition, locationOnDistance);
        this._dialog.Translate3DVectorCtrl1.Value = new TxVector(this._dummyFrame.AbsoluteLocation.Translation);
      }
      else
        this.DestroyManipulator();
      this.BeforeAfterLocationForColoring = this._appManager.GetLocationAfter(locationOperation);
      this.ColorLastBeforeAfterLocation();
    }
    else
    {
      this._dialog.PercentageTxNumericEditBoxCtrl.Enabled = false;
      this._dialog.DistanceTxNumericEditBoxCtrl.Enabled = false;
      this._dialog.Translate3DVectorCtrl1.Enabled = false;
      this._dialog.OkButton.Enabled = false;
      this._dialog.ApplyButton.Enabled = false;
      this.DestroyManipulator();
    }
  }

  public void SetPickMode()
  {
    this.UpdateNumericControlsAccordingToTheRadioButtonCheck();
    this._dialog.OkButton.Enabled = true;
    this._dialog.ApplyButton.Enabled = true;
    this.UncolorLastRelativeLocation();
    this.UncolorLastBeforeAfterLocation();
    TxRoboticSeamLocationOperation relativeLocation = this._dialog.RelativeLocationObjEditBoxCtrl.Object as TxRoboticSeamLocationOperation;
    if (this._dialog.AutomaticRadioButton.Checked)
    {
      this.SetAutomaticLocation();
      if (TxRoboticSeamLocationOperation.op_Inequality(this._automaticRelativeLocation, (ITxObject) null))
        relativeLocation = this._automaticRelativeLocation;
    }
    TxRoboticSeamOperation fromSeamLocation = TxProjectionEx.GetSeamFromSeamLocation(relativeLocation);
    bool flag1 = this._appManager.HasLocationBefore(fromSeamLocation, relativeLocation);
    bool flag2 = this._appManager.HasLocationAfter(fromSeamLocation, relativeLocation);
    if (flag1 | flag2)
    {
      this.RelativeLocationForColoring = relativeLocation;
      this.ColorRelativeLocation();
      if (flag1)
        this.BeforeAfterLocationForColoring = this._appManager.GetLocationBefore(relativeLocation);
      if (flag2)
        this.OtherSublingLocationForColoring = this._appManager.GetLocationAfter(relativeLocation);
      this.ColorLastBeforeAfterLocation();
      this.ShouldRefreshmanipulatorDisplay = true;
      this.ShouldUpadatePositionAndRotationValues = true;
      if (!this._dialog.AutomaticRadioButton.Checked)
      {
        TxTransformation locationOnDistance = this.GetLocationOnDistance();
        TxTransformation absolutePosition = this.CalculateLocationAbsolutePosition(locationOnDistance);
        if (TxTransformation.op_Inequality(absolutePosition, (TxTransformation) null))
        {
          this.PlaceManipulator(absolutePosition, locationOnDistance);
          this._dialog.Translate3DVectorCtrl1.Value = new TxVector(this._dummyFrame.AbsoluteLocation.Translation);
          this._dialog.Translate3DVectorCtrl1.Enabled = true;
        }
        else
          this.DestroyManipulator();
      }
      this._dialog.RelativeLocationObjEditBoxCtrl.LoseFocus();
      this.UnsubscribeForPickListener();
      this.SubscribeForPickListener();
      this.ArePositionRadioButtonsEnabled(true);
    }
    else
    {
      this.DestroyManipulator();
      this._dialog.RelativeLocationObjEditBoxCtrl.Focus();
      this._dialog.Translate3DVectorCtrl1.Enabled = false;
      this._dialog.OkButton.Enabled = false;
      this._dialog.ApplyButton.Enabled = false;
      this.ArePositionRadioButtonsEnabled(false);
    }
  }

  internal void SetAutomaticLocation()
  {
    if (!this._dialog.AutomaticRadioButton.Checked)
      return;
    Cursor current = Cursor.Current;
    Cursor.Current = Cursors.WaitCursor;
    this._automaticRelativeLocation = (TxRoboticSeamLocationOperation) null;
    TxRoboticSeamLocationOperation locationOperation = this._dialog.RelativeLocationObjEditBoxCtrl.Object as TxRoboticSeamLocationOperation;
    if (this._dummyFrame == null && TxRoboticSeamLocationOperation.op_Inequality(locationOperation, (ITxObject) null))
    {
      TxTransformation absoluteLocation = locationOperation.AbsoluteLocation;
      TxTransformation absolutePosition = this.CalculateLocationAbsolutePosition(absoluteLocation);
      if (TxTransformation.op_Inequality(absolutePosition, (TxTransformation) null))
        this.PlaceManipulator(absolutePosition, absoluteLocation);
    }
    if (this._dummyFrame != null && TxRoboticSeamLocationOperation.op_Inequality(locationOperation, (ITxObject) null))
    {
      int automaticLocation = TxProjectionEx.GetAutomaticLocation(locationOperation, this._dummyFrame.AbsoluteLocation.Translation);
      if (automaticLocation > -1)
        this._automaticRelativeLocation = ((ITxOrderedObjectCollection) (locationOperation.Collection as ITxOrderedCompoundOperation)).GetChildAt(automaticLocation) as TxRoboticSeamLocationOperation;
      this._dialog.OkButton.Enabled = true;
      this._dialog.ApplyButton.Enabled = true;
    }
    else if (this._dummyFrame == null)
    {
      this._dialog.OkButton.Enabled = false;
      this._dialog.ApplyButton.Enabled = false;
    }
    Cursor.Current = current;
  }

  public void SetBetween2LocationsMode()
  {
    this.UncolorLastRelativeLocation();
    this.UncolorLastBeforeAfterLocation();
    this.UnsubscribeForPickListener();
    this._dialog.RelativeLocationObjEditBoxCtrl.Focus();
    this.ArePositionRadioButtonsEnabled(true);
    TxRoboticSeamLocationOperation locationOperation = this._dialog.RelativeLocationObjEditBoxCtrl.Object as TxRoboticSeamLocationOperation;
    if (TxRoboticSeamLocationOperation.op_Inequality(locationOperation, (ITxObject) null))
    {
      bool flag = true;
      TxRoboticSeamOperation fromSeamLocation = TxProjectionEx.GetSeamFromSeamLocation(locationOperation);
      if (TxRoboticSeamOperation.op_Inequality(fromSeamLocation, (ITxObject) null))
      {
        this.RelativeLocationForColoring = locationOperation;
        this._dialog.OkButton.Enabled = true;
        this._dialog.ApplyButton.Enabled = true;
        this.UpdateNumericControlsAccordingToTheRadioButtonCheck();
        if (this._dialog.AfterRadioButton.Checked && this._appManager.HasLocationAfter(fromSeamLocation, locationOperation))
        {
          flag = false;
          this.BeforeAfterLocationForColoring = this._appManager.GetLocationAfter(locationOperation);
        }
        else if (this._dialog.BeforeRadioButton.Checked && this._appManager.HasLocationBefore(fromSeamLocation, locationOperation))
        {
          flag = false;
          this.BeforeAfterLocationForColoring = this._appManager.GetLocationBefore(locationOperation);
        }
        else if (this._dialog.AutomaticRadioButton.Checked)
        {
          flag = false;
          this.SetAutomaticLocation();
          this.BeforeAfterLocationForColoring = this._automaticRelativeLocation;
        }
        else
        {
          this._dialog.OkButton.Enabled = false;
          this._dialog.ApplyButton.Enabled = false;
          this._dialog.PercentageTxNumericEditBoxCtrl.Enabled = false;
          this._dialog.DistanceTxNumericEditBoxCtrl.Enabled = false;
          this._dialog.Translate3DVectorCtrl1.Enabled = false;
        }
        if (this._dialog.AfterRadioButton.Checked && !this._appManager.HasLocationAfter(fromSeamLocation, locationOperation))
        {
          this._dialog.PercentageTxNumericEditBoxCtrl.Enabled = false;
          this._dialog.DistanceTxNumericEditBoxCtrl.Enabled = false;
          this._dialog.OkButton.Enabled = false;
          this._dialog.ApplyButton.Enabled = false;
        }
        else if (this._dialog.BeforeRadioButton.Checked && !this._appManager.HasLocationBefore(fromSeamLocation, locationOperation))
        {
          this._dialog.PercentageTxNumericEditBoxCtrl.Enabled = false;
          this._dialog.DistanceTxNumericEditBoxCtrl.Enabled = false;
          this._dialog.OkButton.Enabled = false;
          this._dialog.ApplyButton.Enabled = false;
        }
      }
      if (!flag)
      {
        if (!this._dialog.AutomaticRadioButton.Checked)
        {
          TxTransformation locationOnDistance = this.GetLocationOnDistance();
          TxTransformation absolutePosition = this.CalculateLocationAbsolutePosition(locationOnDistance);
          if (TxTransformation.op_Inequality(absolutePosition, (TxTransformation) null))
          {
            this.ShouldRefreshmanipulatorDisplay = true;
            this.ShouldUpadatePositionAndRotationValues = true;
            this.PlaceManipulator(absolutePosition, locationOnDistance);
            this._dialog.Translate3DVectorCtrl1.Value = new TxVector(this._dummyFrame.AbsoluteLocation.Translation);
          }
          else
            this.DestroyManipulator();
        }
      }
      else
        this.DestroyManipulator();
      this.ColorRelativeLocation();
      this.ColorLastBeforeAfterLocation();
    }
    else
    {
      this.ArePositionRadioButtonsEnabled(false);
      this._dialog.RelativeLocationObjEditBoxCtrl.Focus();
      this._dialog.AfterRadioButton.Checked = true;
      this._dialog.PercentageTxNumericEditBoxCtrl.Enabled = false;
      this._dialog.DistanceTxNumericEditBoxCtrl.Enabled = false;
      this._dialog.OkButton.Enabled = false;
      this._dialog.ApplyButton.Enabled = false;
      this._dialog.Translate3DVectorCtrl1.Enabled = false;
      this.DestroyManipulator();
    }
  }

  private void ArePositionRadioButtonsEnabled(bool areEnabled)
  {
    this._dialog.AfterRadioButton.Enabled = areEnabled;
    this._dialog.BeforeRadioButton.Enabled = areEnabled;
    this._dialog.AutomaticRadioButton.Enabled = areEnabled;
  }

  public void OnSeamLocationChanged(bool isDialogStart = false)
  {
    if (!this.IsMfgLoaded())
      this.SetInsertLocationEnableState(true);
    else if (this.HasMfg3DRepresentation())
    {
      if (this.IsMfgVisible())
        this.SetInsertLocationEnableState(true);
      else if (isDialogStart)
        ((Form) this._dialog).Close();
      else
        this.SetInsertLocationEnableState(false);
    }
    else if (TxMessageBox.Show(StringTable.MFG_IS_WITHOUT_3D_REPRESENTATION_ERROR_MSG, StringTable.MFG_IS_WITHOUT_3D_REPRESENTATION_ERROR_TITLE, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
      this.SetInsertLocationEnableState(false);
    else
      ((Form) this._dialog).Close();
  }

  public void SetPercentageOrDistance()
  {
    this.ShouldRefreshmanipulatorDisplay = true;
    this.ShouldUpadatePositionAndRotationValues = true;
    TxTransformation locationOnDistance = this.GetLocationOnDistance();
    TxTransformation absolutePosition = this.CalculateLocationAbsolutePosition(locationOnDistance);
    if (TxTransformation.op_Inequality(absolutePosition, (TxTransformation) null))
    {
      this.PlaceManipulator(absolutePosition, locationOnDistance);
      this._dialog.Translate3DVectorCtrl1.Value = new TxVector(this._dummyFrame.AbsoluteLocation.Translation);
    }
    else
      this.DestroyManipulator();
  }

  private TxTransformation CalculateLocationRelativeToReferenceLocation(TxTransformation location)
  {
    TxTransformation referenceLocation = (TxTransformation) null;
    try
    {
      TxRoboticSeamLocationOperation seamLocation = this._dialog.RelativeLocationObjEditBoxCtrl.Object as TxRoboticSeamLocationOperation;
      if (TxRoboticSeamLocationOperation.op_Inequality(seamLocation, (ITxObject) null))
      {
        TxRoboticSeamOperation fromSeamLocation = TxProjectionEx.GetSeamFromSeamLocation(seamLocation);
        if (TxRoboticSeamOperation.op_Inequality(fromSeamLocation, (ITxObject) null))
        {
          bool flag1 = !this._dialog.BeforeRadioButton.Checked;
          if (flag1 && !this._appManager.HasLocationBefore(fromSeamLocation, seamLocation) || !flag1 && !this._appManager.HasLocationAfter(fromSeamLocation, seamLocation))
            flag1 = !flag1;
          bool flag2 = TxProjectionEx.WasSeamOperationProjectedAsARC(fromSeamLocation);
          TxTransformation txTransformation1 = (TxTransformation) null;
          if (flag2)
          {
            txTransformation1 = TxProjectionEx.GetArcProjectionOnObject(fromSeamLocation, location, flag1);
          }
          else
          {
            TxTransformation txTransformation2;
            ITxObject itxObject;
            if (TxProjectionEx.GetProjectionOnObject(fromSeamLocation, seamLocation, location.Translation, ref txTransformation2, ref itxObject))
              txTransformation1 = txTransformation2;
          }
          if (TxTransformation.op_Inequality(txTransformation1, (TxTransformation) null))
          {
            TxTransformation txTransformation3 = new TxTransformation((fromSeamLocation.SeamMfgFeature as TxSeamMfgFeature).GetPointOnCurveByDistance(seamLocation.AbsoluteLocation.Translation, 0.0), new TxVector(), (TxTransformation.TxRotationType) 1);
            if (flag2)
            {
              txTransformation3 = TxProjectionEx.GetArcProjectionOnObject(fromSeamLocation, txTransformation3, flag1);
            }
            else
            {
              TxTransformation txTransformation4;
              ITxObject itxObject;
              if (TxProjectionEx.GetProjectionOnObject(fromSeamLocation, seamLocation, txTransformation3.Translation, ref txTransformation4, ref itxObject))
                txTransformation3 = txTransformation4;
            }
            if (TxTransformation.op_Inequality(txTransformation3, (TxTransformation) null))
            {
              TxTransformation txTransformation5 = TxTransformationEx.Delta(txTransformation3, seamLocation.AbsoluteLocation);
              referenceLocation = TxTransformation.op_Multiply(txTransformation1, txTransformation5);
            }
          }
        }
      }
    }
    catch (Exception ex)
    {
    }
    return referenceLocation;
  }

  private TxTransformation GetLocationOnDistance()
  {
    double num1 = 0.0;
    TxTransformation locationOnDistance = (TxTransformation) null;
    TxVector txVector = (TxVector) null;
    TxRoboticSeamLocationOperation targetLocation = this._dialog.RelativeLocationObjEditBoxCtrl.Object as TxRoboticSeamLocationOperation;
    if (TxRoboticSeamLocationOperation.op_Inequality(targetLocation, (ITxObject) null))
    {
      TxRoboticSeamOperation fromSeamLocation = TxProjectionEx.GetSeamFromSeamLocation(targetLocation);
      TxSeamMfgFeature seamMfgFeature = fromSeamLocation.SeamMfgFeature as TxSeamMfgFeature;
      TxVector translation1 = targetLocation.AbsoluteLocation.Translation;
      if (this._dialog.DistanceRadioButton.Checked)
      {
        double num2 = this._dialog.DistanceTxNumericEditBoxCtrl.Value;
        if (this._dialog.BeforeRadioButton.Checked)
          num2 = 0.0 - num2;
        txVector = seamMfgFeature.GetPointOnCurveByDistance(translation1, num2);
      }
      else
      {
        TxRoboticSeamLocationOperation locationOperation = (TxRoboticSeamLocationOperation) null;
        if (this._dialog.BeforeRadioButton.Checked)
          locationOperation = this._appManager.GetLocationBefore(targetLocation);
        else if (this._dialog.AfterRadioButton.Checked)
          locationOperation = this._appManager.GetLocationAfter(targetLocation);
        if (TxRoboticSeamLocationOperation.op_Equality(locationOperation, (ITxObject) null))
        {
          locationOperation = targetLocation;
          num1 = 0.0;
        }
        else if (this._dialog.PercentageRadioButton.Checked)
          num1 = this._dialog.PercentageTxNumericEditBoxCtrl.Value / 100.0;
        else if (this._dialog.PickOnCurveRadioButton.Checked)
        {
          TxRoboticSeamLocationOperation seamLocation = this._dialog.RelativeLocationObjEditBoxCtrl.Object as TxRoboticSeamLocationOperation;
          if (this._appManager.HasLocationBefore(fromSeamLocation, seamLocation) | this._appManager.HasLocationAfter(fromSeamLocation, seamLocation))
            num1 = 1.0;
        }
        if (TxRoboticSeamLocationOperation.op_Inequality(locationOperation, (ITxObject) null))
        {
          TxVector translation2 = locationOperation.AbsoluteLocation.Translation;
          txVector = seamMfgFeature.GetPointOnCurveByRatio(translation1, translation2, num1);
        }
      }
      if (TxVector.op_Inequality(txVector, (TxVector) null))
        locationOnDistance = new TxTransformation(txVector, new TxVector(), (TxTransformation.TxRotationType) 1);
    }
    return locationOnDistance;
  }

  private ITxMfgFeature GetSeamMfgOfRelativeLocation()
  {
    if (this._dialog.RelativeLocationObjEditBoxCtrl != null)
    {
      TxRoboticSeamLocationOperation locationOperation = this._dialog.RelativeLocationObjEditBoxCtrl.Object as TxRoboticSeamLocationOperation;
      if (TxRoboticSeamLocationOperation.op_Inequality(locationOperation, (ITxObject) null))
      {
        TxRoboticSeamOperation fromSeamLocation = TxProjectionEx.GetSeamFromSeamLocation(locationOperation);
        if (TxRoboticSeamOperation.op_Inequality(fromSeamLocation, (ITxObject) null))
          return fromSeamLocation.SeamMfgFeature;
      }
    }
    return (ITxMfgFeature) null;
  }

  private bool IsMfgLoaded()
  {
    return TxSeamMfgFeature.op_Inequality(this.GetSeamMfgOfRelativeLocation() as TxSeamMfgFeature, (ITxObject) null);
  }

  private bool IsMfgVisible()
  {
    TxSeamMfgFeature relativeLocation = this.GetSeamMfgOfRelativeLocation() as TxSeamMfgFeature;
    bool flag = false;
    if (TxSeamMfgFeature.op_Inequality(relativeLocation, (ITxObject) null))
    {
      if (((TxMfgFeature) relativeLocation).Visibility == null)
        flag = true;
      else if (TxMessageBox.Show(StringTable.MFG_IS_BLANKED_ERROR_MSG, StringTable.MFG_IS_BLANKED_ERROR_TITLE, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
      {
        ((TxMfgFeature) relativeLocation).Display();
        flag = true;
      }
    }
    return flag;
  }

  private bool HasMfg3DRepresentation()
  {
    TxSeamMfgFeature relativeLocation = this.GetSeamMfgOfRelativeLocation() as TxSeamMfgFeature;
    bool flag = false;
    if (TxSeamMfgFeature.op_Inequality(relativeLocation, (ITxObject) null) && ((TxMfgFeature) relativeLocation).Visibility != 3)
      flag = true;
    return flag;
  }

  private void SetInsertLocationEnableState(bool shouldEnable)
  {
    if (shouldEnable)
    {
      if (this._dialog.PercentageRadioButton.Checked)
        this.SetPercentageOrDistance();
    }
    else
      this.DestroyManipulator();
    this._dialog.PositionGroupBox.Enabled = shouldEnable;
  }

  public void UnsubscribeForPickListener()
  {
    this._pickListener.Picked -= new TxPickListener_PickedEventHandler(this._pickListener_Picked);
  }

  public void SetPickProviders()
  {
    // ISSUE: unable to decompile the method.
  }

  private void SubscribeForPickListener()
  {
    this._pickListener.Picked += new TxPickListener_PickedEventHandler(this._pickListener_Picked);
  }

  private void _pickListener_Picked(object sender, TxPickListener_PickedEventArgs args)
  {
    if (args.Object != null && args.Object is TxSeamMfgFeature)
    {
      TxRoboticSeamOperation fromSeamLocation = TxProjectionEx.GetSeamFromSeamLocation(this._dialog.RelativeLocationObjEditBoxCtrl.Object as TxRoboticSeamLocationOperation);
      if (TxSeamMfgFeature.op_Equality(args.Object as TxSeamMfgFeature, (ITxObject) fromSeamLocation.SeamMfgFeature))
      {
        TxTransformation projectedLocation = new TxSeamMfgFeatureEx(fromSeamLocation.SeamMfgFeature as TxSeamMfgFeature).ContinuousSeamMfgFeatureProjectPointOnCurve(args.Location);
        TxTransformation absolutePosition = this.CalculateLocationAbsolutePosition(projectedLocation);
        this.ShouldRefreshmanipulatorDisplay = true;
        this.ShouldUpadatePositionAndRotationValues = true;
        if (TxTransformation.op_Inequality(absolutePosition, (TxTransformation) null))
        {
          this.PlaceManipulator(absolutePosition, projectedLocation);
          this._dialog.Translate3DVectorCtrl1.Value = new TxVector(this._dummyFrame.AbsoluteLocation.Translation);
          this.SetAutomaticLocation();
        }
        else
          this.DestroyManipulator();
      }
      else
        this.DisplayErrorMessage();
    }
    else
      this.DisplayErrorMessage();
  }

  public bool OkClicked() => this.CreateLocationOnDummyFrame();

  private bool CreateLocationOnDummyFrame()
  {
    bool locationOnDummyFrame = false;
    TxRoboticSeamLocationOperation relativeLocationInTheSeam = !this._dialog.AutomaticRadioButton.Checked ? this._dialog.RelativeLocationObjEditBoxCtrl.Object as TxRoboticSeamLocationOperation : this._automaticRelativeLocation;
    if (TxRoboticSeamLocationOperation.op_Inequality(relativeLocationInTheSeam, (ITxObject) null) && this._dummyFrame != null)
    {
      TxRoboticSeamOperation fromSeamLocation = TxProjectionEx.GetSeamFromSeamLocation(relativeLocationInTheSeam);
      if (TxRoboticSeamOperation.op_Inequality(fromSeamLocation, (ITxObject) null))
      {
        TxRoboticSeamLocationOperation locationOperation = !this._dialog.BeforeRadioButton.Checked ? this._appManager.CreateSeamLocationAfter(fromSeamLocation, relativeLocationInTheSeam, this._dummyFrame.ProjectedLocation) : this._appManager.CreateSeamLocationBefore(fromSeamLocation, relativeLocationInTheSeam, this._dummyFrame.ProjectedLocation);
        if (TxRoboticSeamLocationOperation.op_Inequality(locationOperation, (ITxObject) null))
        {
          if (this._dialog.UseReferenceLocationPositionCheckBox.Checked)
            locationOperation.AbsoluteLocation = this._dummyFrame.AbsoluteLocation;
          locationOnDummyFrame = true;
        }
      }
    }
    return locationOnDummyFrame;
  }

  internal CApIlisSeamLocationValidator SeamLocationValidator { get; private set; }

  public void TypedValid()
  {
    this.RelativeLocationPicked();
    TxRoboticSeamLocationOperation seamLocation = this._dialog.RelativeLocationObjEditBoxCtrl.Object as TxRoboticSeamLocationOperation;
    if (!TxRoboticSeamLocationOperation.op_Inequality(seamLocation, (ITxObject) null))
      return;
    TxRoboticSeamOperation fromSeamLocation = TxProjectionEx.GetSeamFromSeamLocation(seamLocation);
    if (!TxRoboticSeamOperation.op_Inequality(fromSeamLocation, (ITxObject) null))
      return;
    if (!this._dialog.AfterRadioButton.Checked ? this._appManager.HasLocationBefore(fromSeamLocation, seamLocation) : this._appManager.HasLocationAfter(fromSeamLocation, seamLocation))
    {
      this._dialog.Translate3DVectorCtrl1.Enabled = true;
    }
    else
    {
      this._dialog.PercentageTxNumericEditBoxCtrl.Enabled = false;
      this._dialog.DistanceTxNumericEditBoxCtrl.Enabled = false;
      this._dialog.Translate3DVectorCtrl1.Enabled = false;
      this._dialog.OkButton.Enabled = false;
      this._dialog.ApplyButton.Enabled = false;
      this.DestroyManipulator();
    }
  }

  public void TypedInvalid()
  {
    this._dialog.OkButton.Enabled = false;
    this._dialog.ApplyButton.Enabled = false;
    this._dialog.Translate3DVectorCtrl1.Enabled = false;
    this.ArePositionRadioButtonsEnabled(false);
    this._dialog.PercentageTxNumericEditBoxCtrl.Enabled = false;
    this._dialog.DistanceTxNumericEditBoxCtrl.Enabled = false;
    this.DestroyManipulator();
    this.EmphasizeOnlyRelevantSeam();
    this.UncolorLastRelativeLocation();
    this.UncolorLastBeforeAfterLocation();
    this.OnSeamLocationChanged();
  }

  private void SetSeamLocationValidator()
  {
    this.SeamLocationValidator = new CApIlisSeamLocationValidator();
    this._dialog.RelativeLocationObjEditBoxCtrl.SetValidator((ITxValidator) this.SeamLocationValidator);
  }

  private void ColorRelativeLocation()
  {
    if (!TxRoboticSeamLocationOperation.op_Inequality(this._lastRelativeLocation, (ITxObject) null))
      return;
    TxDisplayableObjectEx.EmphasizeRedObject((ITxDisplayableObject) this._lastRelativeLocation);
    TxApplication.RefreshDisplay();
  }

  private void ColorLastBeforeAfterLocation()
  {
    if (this._dialog.DistanceRadioButton.Checked)
      return;
    if (TxRoboticSeamLocationOperation.op_Inequality(this._lastBeforeAfterLocation, (ITxObject) null))
    {
      TxDisplayableObjectEx.EmphasizeBlueObject((ITxDisplayableObject) this._lastBeforeAfterLocation);
      TxApplication.RefreshDisplay();
    }
    if (!this._dialog.PickOnCurveRadioButton.Checked || !TxRoboticSeamLocationOperation.op_Inequality(this._otherSublingLocationInPickMode, (ITxObject) null))
      return;
    TxDisplayableObjectEx.EmphasizeBlueObject((ITxDisplayableObject) this._otherSublingLocationInPickMode);
    TxApplication.RefreshDisplay();
  }

  private void UncolorLastRelativeLocation()
  {
    if (!TxRoboticSeamLocationOperation.op_Inequality(this._lastRelativeLocation, (ITxObject) null))
      return;
    TxDisplayableObjectEx.StopEmphasizeRedObject((ITxDisplayableObject) this._lastRelativeLocation);
    this._lastRelativeLocation = (TxRoboticSeamLocationOperation) null;
    TxApplication.RefreshDisplay();
  }

  private void UncolorLastBeforeAfterLocation()
  {
    if (TxRoboticSeamLocationOperation.op_Inequality(this._lastBeforeAfterLocation, (ITxObject) null))
    {
      TxDisplayableObjectEx.StopEmphasizeBlueObject((ITxDisplayableObject) this._lastBeforeAfterLocation);
      this._lastBeforeAfterLocation = (TxRoboticSeamLocationOperation) null;
      TxApplication.RefreshDisplay();
    }
    if (!TxRoboticSeamLocationOperation.op_Inequality(this._otherSublingLocationInPickMode, (ITxObject) null))
      return;
    TxDisplayableObjectEx.StopEmphasizeBlueObject((ITxDisplayableObject) this._otherSublingLocationInPickMode);
    this._lastBeforeAfterLocation = (TxRoboticSeamLocationOperation) null;
    TxApplication.RefreshDisplay();
  }

  private void EmphasizeOnlyRelevantSeam()
  {
    this.SetWidthForAllMfgs(1);
    TxSeamMfgFeature relevantSeam = this.GetRelevantSeam();
    if (TxSeamMfgFeature.op_Inequality(relevantSeam, (ITxObject) null))
      relevantSeam.SetLineWidth(3);
    TxApplication.RefreshDisplay();
  }

  private void UnEmphasizeOnlyRelevantSeam()
  {
    if (TxApplication.CommandsManager.IsCommandChecked("CApECMEmphasizeContinuousMfgCmd"))
    {
      this.SetWidthForAllMfgs(3);
    }
    else
    {
      TxSeamMfgFeature relevantSeam = this.GetRelevantSeam();
      if (TxSeamMfgFeature.op_Inequality(relevantSeam, (ITxObject) null))
        relevantSeam.SetLineWidth(1);
    }
    TxApplication.RefreshDisplay();
  }

  private void SetWidthForAllMfgs(int newWidth)
  {
    foreach (ITxObject allSeamMfg in (Collection<ITxObject>) this.GetAllSeamMfgs())
    {
      if (allSeamMfg is TxSeamMfgFeature)
        (allSeamMfg as TxSeamMfgFeature).SetLineWidth(newWidth);
    }
  }

  private TxObjectList GetAllSeamMfgs()
  {
    TxTypeFilter txTypeFilter = new TxTypeFilter();
    txTypeFilter.AddIncludedType(typeof (TxSeamMfgFeature));
    return TxApplication.ActiveDocument.MfgRoot.GetAllDescendants((ITxTypeFilter) txTypeFilter);
  }

  private TxSeamMfgFeature GetRelevantSeam()
  {
    TxSeamMfgFeature relevantSeam = (TxSeamMfgFeature) null;
    if (this._dialog.RelativeLocationObjEditBoxCtrl.Object != null)
    {
      TxRoboticSeamLocationOperation locationOperation = this._dialog.RelativeLocationObjEditBoxCtrl.Object as TxRoboticSeamLocationOperation;
      if (TxRoboticSeamLocationOperation.op_Inequality(locationOperation, (ITxObject) null))
      {
        TxRoboticSeamOperation fromSeamLocation = TxProjectionEx.GetSeamFromSeamLocation(locationOperation);
        if (TxRoboticSeamOperation.op_Inequality(fromSeamLocation, (ITxObject) null))
          relevantSeam = fromSeamLocation.SeamMfgFeature as TxSeamMfgFeature;
      }
    }
    return relevantSeam;
  }

  private void DestroyManipulator()
  {
    if (this._dummyFrame != null)
    {
      this._dummyFrame.DestroyManipulator();
      this._dummyFrame.ProjectedLocation = (TxTransformation) null;
      this._dummyFrame = (CApIlisManipulator) null;
      TxApplication.RefreshDisplay();
    }
    this._dialog.OkButton.Enabled = false;
    this._dialog.ApplyButton.Enabled = false;
  }

  private TxTransformation CalculateLocationAbsolutePosition(TxTransformation projectedLocation)
  {
    TxTransformation absolutePosition = (TxTransformation) null;
    if (TxTransformation.op_Inequality(projectedLocation, (TxTransformation) null))
      absolutePosition = !this._dialog.UseReferenceLocationPositionCheckBox.Checked ? projectedLocation : this.CalculateLocationRelativeToReferenceLocation(projectedLocation);
    return absolutePosition;
  }

  private void PlaceManipulator(
    TxTransformation absoluteLocation,
    TxTransformation projectedLocation)
  {
    if (this._dummyFrame == null)
      this._dummyFrame = new CApIlisManipulator(absoluteLocation);
    else
      this._dummyFrame.ChangeManipulatorLocation(absoluteLocation);
    this._dummyFrame.ProjectedLocation = projectedLocation;
    this._dialog.OkButton.Enabled = true;
    this._dialog.ApplyButton.Enabled = true;
    TxApplication.RefreshDisplay();
  }

  public void HidePath()
  {
    this._objectsVisibilityDict = new Dictionary<string, TxDisplayableObjectVisibility>();
    ITxContinuousOperation continuousOperation = (ITxContinuousOperation) null;
    if (this._dialog.RelativeLocationObjEditBoxCtrl != null && this._dialog.RelativeLocationObjEditBoxCtrl.Object is TxRoboticSeamLocationOperation && (this._dialog.RelativeLocationObjEditBoxCtrl.Object as TxRoboticSeamLocationOperation).Collection is TxRoboticSeamOperation)
      continuousOperation = ((ITxObject) (this._dialog.RelativeLocationObjEditBoxCtrl.Object as TxRoboticSeamLocationOperation).Collection).Collection as ITxContinuousOperation;
    if (continuousOperation != null)
    {
      this._objectsVisibilityDict.Add(((ITxObject) continuousOperation).Id, ((ITxDisplayableObject) continuousOperation).Visibility);
      TxTypeFilter txTypeFilter = new TxTypeFilter();
      txTypeFilter.AddIncludedType(typeof (TxRoboticSeamLocationOperation));
      foreach (ITxObject allDescendant in (Collection<ITxObject>) ((ITxObjectCollection) continuousOperation).GetAllDescendants((ITxTypeFilter) txTypeFilter))
      {
        if (allDescendant is ITxDisplayableObject)
          this._objectsVisibilityDict.Add(allDescendant.Id, (allDescendant as ITxDisplayableObject).Visibility);
      }
      ((ITxDisplayableObject) continuousOperation).Blank();
      foreach (ITxObject itxObject in (this._dialog.RelativeLocationObjEditBoxCtrl.Object as TxRoboticSeamLocationOperation).Collection as TxRoboticSeamOperation)
      {
        if (this._objectsVisibilityDict.ContainsKey(itxObject.Id) && this._objectsVisibilityDict[itxObject.Id] != 2)
          (itxObject as ITxDisplayableObject).Display();
      }
    }
    TxApplication.RefreshDisplay();
  }

  public void ShowPath()
  {
    if (this._objectsVisibilityDict != null)
    {
      ITxContinuousOperation continuousOperation = (ITxContinuousOperation) null;
      if (this._dialog.RelativeLocationObjEditBoxCtrl != null && this._dialog.RelativeLocationObjEditBoxCtrl.Object is TxRoboticSeamLocationOperation && (this._dialog.RelativeLocationObjEditBoxCtrl.Object as TxRoboticSeamLocationOperation).Collection is TxRoboticSeamOperation)
        continuousOperation = ((ITxObject) (this._dialog.RelativeLocationObjEditBoxCtrl.Object as TxRoboticSeamLocationOperation).Collection).Collection as ITxContinuousOperation;
      if (continuousOperation != null)
      {
        if (this._objectsVisibilityDict.ContainsKey(((ITxObject) continuousOperation).Id) && this._objectsVisibilityDict[((ITxObject) continuousOperation).Id] != 2)
          ((ITxDisplayableObject) continuousOperation).Display();
        TxTypeFilter txTypeFilter = new TxTypeFilter();
        txTypeFilter.AddIncludedType(typeof (TxRoboticSeamLocationOperation));
        foreach (ITxObject allDescendant in (Collection<ITxObject>) ((ITxObjectCollection) continuousOperation).GetAllDescendants((ITxTypeFilter) txTypeFilter))
        {
          if (allDescendant is ITxDisplayableObject && this._objectsVisibilityDict.ContainsKey(allDescendant.Id) && this._objectsVisibilityDict[allDescendant.Id] == 2)
            (allDescendant as ITxDisplayableObject).Blank();
        }
        this._objectsVisibilityDict = (Dictionary<string, TxDisplayableObjectVisibility>) null;
      }
    }
    TxApplication.RefreshDisplay();
  }
}
